// ==UserScript==
// @name           Message Manager
// @namespace      http://userscripts.org/users/81292
// @author				 salomone
// @version				 0.4.1.16
// @description    Message subject changer based on keywords
// @include        http://s*.ikariam.*/*view=diplomacyAdvisor*
// @include        http://s*.ikariam.*/*action=Diplomacy*
// @include        http://s*.ikariam.*/*view=sendIKMessage*
// @include        http://s*.ikariam.*/index.php*
// @include        http://s*.ikariam.*/*view=options*
//
// @require        http://messagemanager.googlecode.com/svn/messagemanager/helper_functions.js
// @require        http://messagemanager.googlecode.com/svn/messagemanager/lang_data.js
// @require        http://messagemanager.googlecode.com/svn/messagemanager/init_functions.js
// @require        http://messagemanager.googlecode.com/svn/messagemanager/setup_gui_functions.js
// @require        http://messagemanager.googlecode.com/svn/messagemanager/subject_transform_functi.js
// @require        http://messagemanager.googlecode.com/svn/messagemanager/send_message_functions.js
// @require        http://messagemanager.googlecode.com/svn/messagemanager/addressbook_functions.js
//
//	
// ==/UserScript==
// History:
// v.0.0.3.1 - 19/02/2009
// changes not seen by users
// 	its only to separate functions and making a little base to use resource icons in message subjects
// v.0.0.3.2 - 20/02/2009
// changes not seen by users :
// 	helper and init functions
//	fixed include line
//	two dimensional array for message - icon pairing
//	parameterable icon name for trade messages
//	core for specific message sending with autogenerated subject
//	fix problem which occurs after deleting a message
// changes seen by users :	
//	bulb icon for 'MENTOR'; shield icon for 'SEGITSEG'; wood icon for all trade messages
// v.0.1.0.0 - 21/02/2009
//				/* I think, I can say, it's pure and ugly, but it has enough basic functions to use */ 
//	message type list filled from definied array
//	only one special message marker is allowed ( in case you don't edit the special marker after inserted into the message box)
// v.0.1.0.9 - 21/02/2009
//	added new icon and option for displaying cultural exchange thought
//	fixed include line and resolution of displaying icons after send / reply a message (url changes by system to */index.php)
//	special subject list is hideable and startingstate is controllable with default variable
//	added some comments in source code
//	changed menu text, message text and icon for category FUN
//	added variable to switch on/off case sensitive marker searching
//	optimized marker search in messages (less then half tr elements to examine than before)
// v.0.1.1.3 - 22/02/2009
//	separate, order and group functions
//	refactor marker menu creator function, usable from multiple pages
//	added marker message availability on simple sendMessage page
//	added include line to enable marker list on simple sendMessage page
// v.0.2.0.1 - 22/02/2009
//	added a "pop-up" div linked to onMouse action on sell/buy/exchange menus to define the exact types of resources in trade
//	added some extension to display the exact types of resources in message subjects. if no exact type set, gold is displayed
//	added clear marker and clear message elements in the list
// v.0.2.0.3 - 24/02/2009
//	put Message Manager menu into separated box 
//	fixed the bug : no menu on sendAlly page
//	made a very-very simple div to close the bottom of the Message Manager menu
//	sendMessage and sendAllyMessage pages use the same, common function to make and display the Message Manager menu
//	confirm message appears using the 'Delete whole message text' option
//	basics of outer text file (to ease down translating) done /* can't see from this code version */
//	new category has been inserted. It's name is SENATE, it's icon is crown.
// v.0.2.0.5 - 26/02/2009
//	source code is more readable, I made some functions to make <code>manageMailBoxMessages()</code> function readable
//	wrote some helper functions to move in hierarchy and get some nodes by name
//	allymessages automatically checked, if they don't contain any of the markers. see notes at <code>makeTickInCheckbox()</code> function
//	message marker will placed on the very first characters of the message. it search for all of the message. in case of change, deletes the old and put the new starting at the first character
//	half fixed gui when selecting trade goods. imported picture from Ikariam is too wide//
// v.0.2.0.9 - 02/03/2009
//	* source code is refactored to outer files depending on it's task
//	* translation keeping is easier due to separated files
//	* made an empty base file for setup gui
// v.0.3.1.6 - 10/03/2009
//	* setup gui is working
//	* server independence addressbook is working, but sometimes lag causes slips in getting user id -> not available yet, working on timing option
// v.0.3.1.7 - 10/03/2009
//	* file name cutted bugfix
// v.0.3.3.5 - 23/03/2009
//	* setup moved to options page -> full reinstall required
//	* incoming and outgoing message list is sizeable, maybe sometimes links don't work properly..
//	* rewrited subject changer engine -> regexp and xpath technics are used now insted of indexof
//	* new extra option -> you can define ONE word which appears in the subject 
// v.0.3.3.7
//	* fixed bug : CUSTOM message subject got exception, when you wrote more than one word in the pop up div
//	* dropped some unnecessary functions, variables 
//	* replaced get*InLang() to get*InLang(KEYNAME) and drop the additional variables from init
//	* replaced most of getElementById() to XPath
//	* added new option: vote
// v.0.3.3.9
//	* added language (server domain) specific keywords 
//	* added language (server domain) specific resource names
// v.0.4.0.2
//	* added addressbook pane with add user box to send message page
//	* added addressbook on options page with remove user from addressbook option
//	* added multiple recipient options on send message page
//	* added 'send ally message' button on send message pane (you can easily send a reply to the alliance)
//	* fixed id mapping on outbox page when getting more than 10 messages / page
// v.0.4.0.3
//	* got new host, I hope, it will work for a long-long time
// v.0.4.0.4
//	* fix addressbook entries removing on options page
//	* addressbook and multiple recipients are disabled on sending message page due to 
// v.0.4.0.5
//	* fixed bugs caused by Ikariam v.0.3.1.
//	* user defined keywords are available
// v.0.4.0.6
//	* minor bugfix
// v.0.4.0.7
//	* added spanish translation (thx 2 Rada974)
// v.0.4.0.78
//	* bugfix, FF 3.5.x stricter XPath expression checking
// v.0.4.0.9
//	* minor bugfix
//	* localized dateformat is available
//	* added partial korean and romanian translations
// v.0.4.0.10
//	* complemented and fixed Korean translation
// v.0.4.0.11
//	* added danish tranlation, thx 2 Loppe
// v.0.4.1.11
//	* added language selector drop-down list on options page
// v.0.4.1.12
//	* changed loc from "http://salomone.yourfreehosting.net/MessageManager/" to "http://messagemanager.googlecode.com/svn/messagemanager/"
// v.0.4.1.13 - 13/12/2009
//	* added BIRTHDAY keyword with encoded picture
// v.0.4.1.15 - 18/02/2010
//	* added subject change feature to messages w/o keyword. replaces the subject to [MESSAGE_TYPE_CHAR_BASED_ON_LANG] - First 70 chars of message
// v.0.4.0.16 - 15/04/2010
//	* added greek tranlation, thx 2 BillyCool



// you can contact me here : salomone[DOT]calabrezi[AT]gmail[DOT]com
//	TODO (ONLY IN JULY) make cleaning in initDefaultSubjectIcons();
//	TODO (ONLY IN JULY) make cleaning in initResourceNamesForAdditionalParams();
//	TODO (ONLY IN JULY) make cleaning for CUSTOM_KEYWORD and HUN_CUSTOM_KEYWORD
//
// Plans :
// * append some extra functions to the drop down list on the message viewing page like 'check all ally messages', 'check all non special messages'..
// * create an address-book like working with direct recipient list ( like island message script )
// * create a GUI and allow to users to define own additional styles with sender (user name based) definitions
// * auto draft save option, it can be load instead of the current message on the message editor screen
// >>>>> * convert island, city names into links in messages - just need a format
// Implemented plans : 
// * insert resource icon into message subject -> ready on 20/02/2009
//	@deprecated -> instead of drop-down list, array based <ul>, <li> list will be used in future
// * create drop-down list to insert keywords into to message before sending -> simple list with basic options implemented on 21/02/2009
// * create option in the list to	- delete marker			 -> ready on 22/02/2009
//									- empty message box	-> ready on 22/02/2009
// * separate functions to outer files, based on their task -> ready on 02/03/2009
// * (I HOPE IT WILL WORK SUCCESFULL) create an outer languge file to make the script language oriented. language selecting will based on server domain. override and default option will be switchable from variable -> ready on 02/03/2009
// * make message list size changeable with a 10 step factor -> ready on 22/03/2009

/*

Main function calls

*/

GM_addStyle("#container #container2 #mainview .contentBox01 table#messages td { padding: 2px 0px}");

if ( url.indexOf('view=diplomacyAdvisor') > 0  || url.indexOf('action=Diplomacy') > 0 || ( url.indexOf('index.php') > 0 && checkIsAnyMessageTableOnScreen() ) )	{		
	if ( pagesToLoad > 1 ) 	{
		extendMessageList();
	}
	else	{
		manageMailBoxMessages2();
	}
}

if ( url.indexOf('view=sendIKMessage') > 0 && url.indexOf('oldView=sendIKMessage') < 0)	{
	placeExtraFunctionBoxOnPage();
}

if ( url.indexOf('view=options') > 0  )	{		
	generateMySetupBoxOnOptionsPage();
}